<?php
$id = $this->id;
$form = $this->form;
?>
<?php
$form->setAttribute('action', '#');
$form->setAttribute('class', 'dialog-form');
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('site_id'));
?>
<div class="row">
    <span class="label">Libellé</span>
    <?php echo $this->formText($form->get('libelle')); ?>
</div>
<div class="row">
    <span class="label">Adresse</span>
    <?php echo $this->formTextarea($form->get('adresse')); ?>
</div>
<input type="submit" value="Enregistrer" onclick="return saveSite();" class="button" style="float:right">
<?php
echo $this->form()->closeTag();
?>
<script type="text/javascript">
    $('#site').submit(function(){
        return saveSite();
    });
    function saveSite()
    {
        var urlSave = '<?php echo $this->url('GRH/default', array('controller' => 'site', 'action' => 'edit', 'id' => $id)); ?>';
        var formData = $('#site').serialize();
        var ajax = $.ajax({
            type: 'post',
            url: urlSave,
            data: formData
        });
        ajax.success(function(data){
            //alert($('#site #libelle').val());
            $('#libelle-<?php echo $id; ?>').html($('#site #libelle').val());
            $('#adresse-<?php echo $id; ?>').html($('#site #adresse').val());
            $('#grh-dialog').dialog('close');
        });
        ajax.error(function(){
            alert('Une erreur est survenue');
        });
        return false;
    }
</script>